<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	    .errorText
	    {
	        color:red;
	    }
    </style>
</head>

<body>
	<form id="form1" method="post">
		<p style="margin-left: 20px;"><label>角色名称：</label>
			<input id="textbox1"  name="name" class="mini-textbox" errorMode="none" onvalidation="checkValidation" requiredErrorText="角色名称不能为空" required="true" vtype="rangeLength:0,50" style="width: 180px;" />
			<span id="name_error" style="margin-left:60px;" class="errorText" ></span>
		</p>
		<p style="margin-left: 20px;"><label>请输入描述信息(备注)：</label>
			<input id="textarea1" name="description" class="mini-textarea" style="width: 245px; "/>
		</p>
	</form>
    <p style="margin-left: 35px;">
    	<a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>
    	<a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>
    </p>
</body>

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	function SaveData() {
        var o = form.getData(true);            
        form.validate();
        if (form.isValid() == false) return;
        var name = mini.get("textbox1").getValue();
        $.post("medical_include_role.do", {name: name}, function(text) {
        	if(text.success) {
        		save(o);
        	} else {
        		mini.alert('此角色已存在!');
        	}
        }, "json");
    }
	
	function save(o) {
		$.ajax({
            url: "medical_role_save.do",
			type: 'post',
			dataType: 'json',
            data: o,
            cache: false,
            success: function (text) {
            	if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误，请重新添加");
	            }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
            }
        });
	}
	
	function onOk(e) {
        SaveData();
    }
	
	function SetData(data){
	     data = mini.clone(data);
	}
	
	function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
	
	function onCancel(e) {
        CloseWindow("cancel");
    }

   	function updateError(e) {
	    var id =e.sender.name + "_error";
	    var el = document.getElementById(id);
	    if (el) {
	        el.innerHTML =e.errorText;
	    }
   	}
   
   	function checkValidation(e) {                  
  		updateError(e);
   	}
   	
</script>